/*
 * Copyright (C) 2008 Universidade Federal de Campina Grande
 *  
 * This file is part of OurGrid. 
 *
 * OurGrid is free software: you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License as published by the Free 
 * Software Foundation, either version 3 of the License, or (at your option) 
 * any later version. 
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT 
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
 * for more details. 
 * 
 * You should have received a copy of the GNU Lesser General Public License 
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 * 
 */
package org.ourgrid.common.interfaces;

import java.io.Serializable;
import java.util.List;

import org.ourgrid.common.interfaces.to.GridProcessAccounting;
import org.ourgrid.common.interfaces.to.WorkAccounting;

import br.edu.ufcg.lsd.commune.api.Remote;

/**
 * <p>
 * Represents an accounting information receiver. This interface is implemented
 * on the Peer module to receive accounting information from both Mygrid and
 * Worker. As soon as a replica finishes the accounting information must be
 * sent.
 * <p>
 * The following pieces of information are:
 * <ul>
 * <li> Execution time of replica
 * <li> Amount of transfered data
 * <li> A <code>ReplicaHandle</code>
 * <li> An identification of the worker on which the replica has executed
 * (WorkerID)
 * <li> An identification of the request (requestID)
 * </ul>
 */
@Remote
public interface AccountingAggregator extends Serializable {
	
	/**
	 * This method is periodically called by the worker, to inform the balance
	 * decrement of the consumers.
	 * 
	 * @param consumersBalances A map whose key is the consumer's public key 
	 * 			and the value is its balance.
	 */
	void reportWorkAccounting( List<WorkAccounting> consumersBalances );
	
	/**
	 * This method is called by MyGrid, after every replica finish.
	 * If the provider is a remote peer, then the balance is stored to have its
	 * relative power calculated and incremented in the provider balance.
	 * Else, if the is the local peer, its balance is stored to server as a
	 * reference on the relative power calculation.
	 * These temporary data are stored until the request finish. After this, 
	 * they are erased.
	 * 
	 * @param replicaAccounting Replica accounting data, composed of:
	 *    The request which the replica belongs to;
	 *    The public key of the peer which provided the worker that executed 
	 *    the replica;
	 *    The replica balance, which will be incremented for the provider
	 */
	void reportReplicaAccounting( GridProcessAccounting replicaAccounting );
	
}
